<?php
namespace App\Domain\Appfc114;

use App\Model\Appfc114\User as ModelUser;
use App\Domain\Appfc114\QueryCommon;



class User  {

    protected $query;

    function __construct() {
        $this->query = new QueryCommon();
    }

    public function getDetailByName($user_name){
        $model = new ModelUser();
        return $model->getDetailByName($user_name);
    }


    public function getDetail($id,$field="id"){
       // $data = $this->FilterField("wx_user",["id"=>11]);
        $model = new ModelUser();
        return $model->getDetail($id,$field);
    }

    public function add($params){
        $data = $this->query->FilterField("wx_user",$params);
        $model = new ModelUser();
        return $model->insertGetId($data);
    }

    public function update($params,$user_id){
        $data = $this->query->FilterField("wx_user",$params);
        $model = new ModelUser();
        return $model->where("id",$user_id)->update($data);
    }

    public function getList($state, $page, $perpage) {
        $rs = array('items' => array(), 'total' => 0);

        $model = new ModelUser();
        $items = $model->getListItems($state, $page, $perpage);
        $total = $model->getListTotal($state);

        $rs['items'] = $items;
        $rs['total'] = $total;

        return $rs;
    }

}
